﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Test.Model;

namespace Test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string path = Vincent._Utility.GetWebApplicationRootPath() + @"config\PositionDefaultSys.config";

            List<PositionDefaultSys> _positionList = Vincent._Xml.SerializeXmlToObj<List<PositionDefaultSys>>(path);

               
            //#region 图片信息

            //// 图片及文件信息
            //string[] fileControlName = HttpContext.Current.Request.Files.AllKeys;

            //string[] smallurlfile = null;        // 小图
            //string[] bigurlfile = null;          // 大图
            //string[] filesize = null;            // 图片大小

            //if (HttpContext.Current.Request.Files.Count > 0)
            //{
            //    string temp_smallurlfile = Vincent._Request.GetStringForm("hSmallurlfile", "");     // 小图
            //    string temp_bigurlfile = Vincent._Request.GetStringForm("hBigurlfile", "");         // 大图
            //    string temp_filesize = Vincent._Request.GetStringForm("hFilesize", "");            // 图片大小

            //    int num = 0;
            //    for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
            //    {
            //        HttpPostedFile file = HttpContext.Current.Request.Files[i];

            //        if (!Vincent._Utility.Regex_IsContains(fileControlName[i], @"file[0-9]"))
            //            continue;

            //        num = Vincent._Utility.Regex_GetNumToString(fileControlName[i]) - 1;

            //        if (file == null)
            //            continue;
            //        num++;

            //        string _bigurlfile = "";
            //        string _smallurlfile = "";
            //        int _filesize = 0;
            //        byte[] b = null;
            //        bool isUploadSuccess = false;    // 是否上传成功

            //        if (file.ContentLength > 0)
            //        {
            //            try
            //            {
            //                // 保存图片
            //                string errormsg = "";

            //                string fileName = file.FileName;
            //                b = new byte[file.ContentLength];
            //                System.IO.Stream fs = null;
            //                fs = (System.IO.Stream)file.InputStream;
            //                fs.Read(b, 0, file.ContentLength);

            //                Upload(@"E:\Vincent\Upload\img" + i + ".jpg", b, ref errormsg);

            //            }
            //            catch (Exception ex)
            //            {
            //                Console.WriteLine("添加资源-上传图片:" + ex);
            //            }

            //            // 本地测试用
            //            //isUploadSuccess = true;
            //            //_bigurlfile = "../images/main_03.gif";
            //            //_smallurlfile = "../images/main_03.gif";
            //            if (isUploadSuccess)
            //            {
            //                temp_bigurlfile += (_bigurlfile + "|");
            //                temp_smallurlfile += (_smallurlfile + "|");
            //                temp_filesize += (_filesize + "|");
            //            }
            //        }
            //    }

            //    smallurlfile = Vincent._Utility.GetStringBySplit(temp_smallurlfile, '|');      // 小图
            //    bigurlfile = Vincent._Utility.GetStringBySplit(temp_bigurlfile, '|');          // 大图
            //    filesize = Vincent._Utility.GetStringBySplit(temp_filesize, '|');             // 图片大小
            //}

            //#endregion
        }

        public static bool Upload(string saveFilePath, byte[] files, ref string errormsg)
        {
            bool IsTrue = false;
            if (Vincent._IO.File.CreateDirectory(System.IO.Path.GetDirectoryName(saveFilePath)))
            {
                System.IO.FileStream fileStream = null;
                try
                {
                    fileStream = new System.IO.FileStream(saveFilePath, System.IO.FileMode.CreateNew);
                    fileStream.Write(files, 0, files.Length);
                    IsTrue = true;
                }
                catch (Exception exp) { IsTrue = false; errormsg = exp.Message; }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Close();
                        fileStream.Dispose();
                    }
                }
            }
            return IsTrue;
        }
       
    }
}
